import { Input, Row, Col, Form, notification } from 'antd';
import React, { useEffect, useState } from 'react';
import '@ant-design/compatible/assets/index.css';
import styles from './AuditForms.less';
import router from 'umi/router';
const FormItem = Form.Item
const BasisMesForm = props => {
    const basisData = props.allDatas;

    const [accidentType, setAccidentType] = useState('');

    const [toaccidentId, setToAccidentId] = useState('');

    useEffect(() => {
      setAccidentType(basisData.accidentType || ''); // 事故单类型
      setToAccidentId(basisData.accidentId || ''); // 事故单ID
    }, [basisData])

    return (
      <div  className='formItems'>
        <Form >
          <Row gutter={16}>
            <Col md={6} sm={12}>
                <FormItem  label='补偿类型：' >
                    {basisData?.payType === '0' ?<Input value='不正常航班' disabled/>  : null}
                    {basisData?.payType === '1' ?<Input value='异常行李' disabled/>  : null}
                    {basisData?.payType === '2' ?<Input value='旅客超售' disabled/>  : null}
                </FormItem>
            </Col>
              <Col md={6} sm={12}>
                <FormItem  label='补偿单号：'>
                  <Input value={basisData?.orderId} disabled/>
                </FormItem>
            </Col>
                <Col md={6} sm={12}>
                  <FormItem label=
                    {
                      <span>事故单号{basisData&&basisData?.payType&&basisData?.payType !=='0'
                      ? <span style={{cursor:'pointer',textDecoration:'underline',color:'#E13B3B',marginLeft: '10px'}}
                          onClick={() =>{
                            let resourceStr = window.localStorage.getItem('resource');
                            // 不正常航班补偿0、异常行李1、旅客超售2
                            if (basisData?.payType==='1') {
                              const urlObj = {
                                '1': '/banksearchSystem/inPortBaggageManagement/damagedBaggageManagement',
                                '2': '/banksearchSystem/inPortBaggageManagement/lessBaggageManagement',
                                '6': '/banksearchSystem/inPortBaggageManagement/internalMissingManagement',
                                '7': '/banksearchSystem/outPortBaggageManagement/damagedBaggageManagement'
                              }
                              // 对行查的页面鉴权
                              let toPathUrl = urlObj[accidentType + ''];
                              if (resourceStr.indexOf(toPathUrl) == -1) {
                                return  notification.info({
                                  message: '您当前无权限进行查看',
                                });
                              }
                              if (toPathUrl) {
                                window.sessionStorage.setItem('isFromCompensate','1');
                                router.push({
                                  pathname: toPathUrl,
                                  state: {
                                    accidentId: toaccidentId
                                  }
                                })
                              }
                              // sessionStorage.setItem('firstLoad', '1')
                              // router.push({
                              //   pathname: "/compensation/luggageindex",
                              //   state: {
                              //     accidentId:basisData?.accidentId,
                              //     flightDate:basisData?.flightDate,
                              //     flightNo:basisData?.flightNo
                              //   }
                              //   })
                            }
                            if (basisData?.payType==='2') {
                              if (resourceStr.indexOf('"path":"/compensation/oversaleindex') == -1) {
                                return  notification.info({
                                  message: '您当前无权限进行查看',
                                });
                              }
                              sessionStorage.setItem('firstLoad', '1')
                              router.push({
                                pathname: '/compensation/oversaleindex',
                                state: {
                                  accidentId:basisData?.accidentId,
                                  flightDate:basisData?.flightDate,
                                  flightNo:basisData?.flightNo
                                }
                                })
                            }
                            }}>查看事故单</span>
                      : ''}</span>
                    }
                  >
                    <Input value={basisData?.accidentId} disabled/>
                  </FormItem>
              </Col>
                <Col md={6} sm={12}>
                  <FormItem   label='服务航站：'>
                    <Input value={basisData?.serviceSegment} disabled/>
                  </FormItem>
              </Col>
          </Row>
          <Row gutter={16}>
            <Col md={6} sm={12}>
              <FormItem   label='航班号：'>
                <Input value={basisData?.flightNo} disabled/>
              </FormItem>
            </Col>
            <Col md={6} sm={12}>
              <FormItem   label='航班日期：'>
                <Input value={basisData?.flightDate} disabled/>
              </FormItem>
            </Col>
            <Col md={12} sm={24}>
              <FormItem label='航段：' >
                <Input value={basisData?.choiceSegment} disabled/>
              </FormItem>
            </Col>
          </Row>
          <Row gutter={16}>
            <Col md={6} sm={12}>
              <FormItem   label='飞机号：'>
                <Input value={basisData?.planeCode} disabled/>
              </FormItem>
            </Col>
            <Col md={6} sm={12}>
              <FormItem   label='预计起飞：'>
                <Input value={basisData?.etd} disabled/>
              </FormItem>
            </Col>
            <Col md={6} sm={12}>
              <FormItem   label='计划起飞：'>
                <Input value={basisData?.std} disabled/>
              </FormItem>
            </Col>
            <Col md={6} sm={12}>
              <FormItem   label='延误时长：'>
                <Input value={basisData?.delayTime} disabled/>
              </FormItem>
            </Col>
          </Row>
          <Row>
            <Col md={24} sm={24}>
              {
                basisData?.payType === '0'
                ? <FormItem  label='延误原因：'>
                    <Input value={basisData?.lateReason} disabled/>
                  </FormItem>
                :<FormItem  label='备注：'>
                <Input value={basisData?.remark} disabled/>
              </FormItem>
              }
            </Col>
          </Row>
        </Form>
       </div>
     )
  }

export default BasisMesForm
